<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	{include="style"}
	<style>
		.layui-form-item .layui-input-inline {
			width: 210px;
		}

		input:read-only:not(.layui-unselect) {
			background-color: #eee;
		}

		td div:not(:first-child) .layui-input {
			margin-top: 10px;
		}

		.layui-input:not(:first-child) {
			margin-top: 10px;
		}

		.layui-textarea {
			margin-top: 10px;
		}

		td label {
			vertical-align: -3px;
		}
	</style>
</head>

<body>
	<div class="x-nav">
		<span class="layui-breadcrumb">
			<a><cite>{fun JZLANG('首页')}</cite></a>
			<a><cite>{fun JZLANG('系统扩展')}</cite></a>
			<a><cite>{fun JZLANG('模块管理')}</cite></a>
			<a><cite>{fun JZLANG('字段管理')}</cite></a>
			<a><cite>{fun JZLANG('新增字段')}</cite></a>
		</span>
		<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="{fun JZLANG('刷新')}"><i class="iconfont" style="line-height:30px">&#xe6aa;</i></a>
	</div>
	<div class="x-body">
		<form class="layui-form layui-form-pane">
			<input type="hidden" name="go" value="1" />
			<input type="hidden" name="molds" value="{$molds}" />

			<div class="layui-tab">
				<ul class="layui-tab-title">
					<li class="layui-this">{fun JZLANG('基本信息')}</li>
					{if($molds=='level')}
					<li>{fun JZLANG('角色绑定')}</li>
					{else}
					<li>栏{fun JZLANG('目绑定')}</li>
					{/if}
				</ul>
				<div class="layui-tab-content">
					<div class="layui-tab-item layui-show">
						<div class="layui-form-item">
							<label for="fieldname" class="layui-form-label"><span class="x-red">*</span>{fun JZLANG('字段名称')}</label>
							<div class="layui-input-inline">
								<input type="text" id="fieldname" name="fieldname" required="" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux">{fun JZLANG('简短的名称')}</div>
						</div>
						<div class="layui-form-item">
							<label for="field" class="layui-form-label"><span class="x-red">*</span>{fun JZLANG('字段标识')}</label>
							<div class="layui-input-inline">
								<input type="text" id="field" name="field" autocomplete="off" required="" lay-verify="required" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux">{fun JZLANG('只能英文字母[或者后面+数字]，必须含有英文字母，小写字母，简短')}</div>
						</div>
						<div class="layui-form-item" pane>
							<label for="fieldtxt" class="layui-form-label">
								<span class="x-red">*</span>{fun JZLANG('字段类型')}
							</label>
							<div class="layui-input-block" style="padding:0 10px;">
								<table class="layui-table">
									<tbody>
										<tr>
											<td>{fun JZLANG('选择')}</td>
											<td>{fun JZLANG('内容')}</td>
											<td>{fun JZLANG('说明')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" checked value="1" /><label>{fun JZLANG('单行文本')}</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_1" value="255"></div></td>
											<td>{fun JZLANG('单行文本')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="2" /><label>{fun JZLANG('多行文本')}</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_2" value="500"></div></td>
											<td>{fun JZLANG('多行文本')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="3" /><label>{fun JZLANG('带编辑器文本')}</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_3" value="{fun JZLANG('不限')}" readonly></div></td>
											<td>{fun JZLANG('带编辑器文本')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="15" /><label>{fun JZLANG('多行动态新增')}</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_15" value="{fun JZLANG('不限')}" readonly></div></td>
											<td>{fun JZLANG('可以在页面动态新增内容输入框')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="4" /><label>{fun JZLANG('11位数字')}</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_4" value="11"></div></td>
											<td>{fun JZLANG('只能填写数字，长度不能超过11位')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="14" /><label>{fun JZLANG('两位小数')}</label></td>
											<td>
												<div><input type="text" class="layui-input" name="fieldlong_14" value="10,2"></div>
												<div><input type="text" class="layui-input" name="body_14" value="0.00"></div>
											</td>
											<td>{fun JZLANG('金钱，小数等，保留2位')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="11" /><label>{fun JZLANG('日期时间')}</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_11" value="11" readonly></div></td>
											<td>{fun JZLANG('时间日期')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="5" /><label>{fun JZLANG('单图')}</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_5" value="255"></div></td>
											<td>{fun JZLANG('单图片')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="6" /><label>{fun JZLANG('多图')}</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_6" value="{fun JZLANG('不限')}" readonly></div></td>
											<td>{fun JZLANG('多图片，图集')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="7" /><label>{fun JZLANG('单选下拉')}</label></td>
											<td>
												<div><input type="text" class="layui-input" name="fieldlong_7" value="500"></div>
												<div><textarea placeholder="{fun JZLANG('红=1,黄=2')}" name="body_7" class="layui-textarea"></textarea></div>
											</td>
											<td>{fun JZLANG('单项选择，下拉选择，如：红=1,黄=2,蓝=3')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="12" /><label>{fun JZLANG('单选按钮')}</label></td>
											<td>
												<div><input type="text" class="layui-input" name="fieldlong_12" value="500"></div>
												<div><textarea placeholder="{fun JZLANG('红=1,黄=2')}" name="body_12" class="layui-textarea"></textarea></div>
											</td>
											<td>{fun JZLANG('单项选择，按钮选择，如：红=1,黄=2,蓝=3')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="8" /><label>{fun JZLANG('多选按钮')}</label></td>
											<td>
												<div><input type="text" class="layui-input" name="fieldlong_8" value="500"></div>
												<div><textarea placeholder="{fun JZLANG('红=1,黄=2')}" name="body_8" class="layui-textarea"></textarea><div>
											</td>
											<td>{fun JZLANG('多项选择，如：红=1,黄=2,蓝=3')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="9" /><label>{fun JZLANG('单文件')}</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_9" value="255"></div></td>
											<td>{fun JZLANG('一个附件，压缩包，Excel，Word文档')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="10" /><label>{fun JZLANG('多文件')}</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_10" value="{fun JZLANG('不限')}" readonly></div></td>
											<td>{fun JZLANG('多个附件，压缩包，Excel，Word文档')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="13" /><label>{fun JZLANG('模块内容关联')}</label></td>
											<td>
												<div><input type="text" class="layui-input" name="fieldlong_13" value="11"></div>
												<div>
													<select name="molds_select" id="molds_select">
														<option>{fun JZLANG('请选择关联模块')}</option>
														{loop table="molds" as="v"}
														<option value="{$v['id']}">{$v['name']}</option>
														{/loop}
													</select>
													<input type="text" placeholder="{fun JZLANG('列表显示字段')}" class="layui-input" name="molds_list_field" id="molds_list_field">
												</div>
											</td>
											<td>{fun JZLANG('单选关联，可以直接调用关联模块内容列表，列表显示对应字段内容')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="16" /><label>{fun JZLANG('模块内容关联（多选）')}</label></td>
											<td>
												<div><input type="text" class="layui-input" name="fieldlong_16" value="255"></div>
												<div>
													<select name="molds_select_muti" id="molds_select_muti">
														<option>{fun JZLANG('请选择关联模块')}</option>
														{loop table="molds" as="v"}
														<option value="{$v['id']}">{$v['name']}</option>
														{/loop}
													</select>
													<input type="text" placeholder="{fun JZLANG('列表显示字段')}" class="layui-input" name="molds_list_field_muti" id="molds_list_field_muti">
												</div>
											</td>
											<td>{fun JZLANG('多选关联，可以直接调用关联模块内容列表，列表显示对应字段内容')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="21" /><label>{fun JZLANG('栏目内容关联')}</label></td>
											<td>
												<div><input type="text" class="layui-input" name="fieldlong_21" value="11"></div>
												<div>
													<select name="molds_select_tid" lay-search id="molds_select_tid">
														<option>{fun JZLANG('请选择关联栏目')}</option>
														{foreach $classtypetree as $vs}
														<option value="{$vs['id']}">{fun str_repeat('&nbsp;&nbsp;',$vs['level'])}{if($vs['haschild'])}|——{else}{if($vs['level'])}|——{/if}{/if}{$vs['classname']}</option>
														{/foreach}
													</select>
													<input type="text" placeholder="{fun JZLANG('列表显示字段')}" class="layui-input" name="molds_list_field_tid" id="molds_list_field_tid">
												</div>
											</td>
											<td>{fun JZLANG('栏目关联单选，可以直接绑定某个栏目下的内容，包括子栏目')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="20" /><label>{fun JZLANG('栏目内容关联（多选）')}</label></td>
											<td>
												<div><input type="text" class="layui-input" name="fieldlong_20" value="255"></div>
												<div>
													<select name="molds_select_tid_muti" lay-search id="molds_select_tid_muti">
														<option>{fun JZLANG('请选择关联栏目')}</option>
														{foreach $classtypetree as $vs}
														<option value="{$vs['id']}">{fun str_repeat('&nbsp;&nbsp;',$vs['level'])}{if($vs['haschild'])}|——{else}{if($vs['level'])}|——{/if}{/if}{$vs['classname']}</option>
														{/foreach}
													</select>
													<input type="text" placeholder="{fun JZLANG('列表显示字段')}" class="layui-input" name="molds_list_field_tid_muti" id="molds_list_field_tid_muti">
												</div>
											</td>
											<td>{fun JZLANG('栏目关联多选，可以直接绑定某个栏目下的多个内容，包括子栏目')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="17" /><label>{fun JZLANG('系统栏目')} [ tid ]</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_17" value="11" readonly></div></td>
											<td>{fun JZLANG('系统栏目，不可修改')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="18" /><label>{fun JZLANG('系统副栏目')} [ tids ]</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_18" value="255" readonly></div></td>
											<td>{fun JZLANG('系统副栏目，不可修改')}</td>
										</tr>
										<tr>
											<td><input type="radio" name="fieldtype" value="19" /><label>{fun JZLANG('系统TAG')} [ tags ]</label></td>
											<td><div><input type="text" class="layui-input" name="fieldlong_19" value="255" readonly></div></td>
											<td>{fun JZLANG('系统TAG，不可修改')}</td>
										</tr>
									</tbody>
								</table>
							</div>
						</div>
						<div class="layui-form-item">
							<label for="vdata" class="layui-form-label">
								<span class="x-red"></span>{fun JZLANG('默认值')}
							</label>
							<div class="layui-input-inline">
								<input type="text" id="vdata" name="vdata" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux">{fun JZLANG('默认字段值，不填默认int类型的值是0，string类型的值是null。多选参数的值是两边带【,】，如【,1,】表示值为1')}</div>
						</div>
						<div class="layui-form-item">
							<label for="tips" class="layui-form-label">
								<span class="x-red"></span>{fun JZLANG('字段提示')}
							</label>
							<div class="layui-input-inline" style="width:600px;">
								<input type="text" id="tips" name="tips" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux">{fun JZLANG('用于填写时的提示信息，50字以内')}</div>
						</div>
						<div class="layui-form-item">
							<label for="orders" class="layui-form-label">
								<span class="x-red"></span>{fun JZLANG('表单排序')}
							</label>
							<div class="layui-input-inline">
								<input type="number" id="orders" value="100" name="orders" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux">{fun JZLANG('数字越大越靠前')}</div>
						</div>
						<div class="layui-form-item" pane>
							<label for="ismust" class="layui-form-label">
								<span class="x-red"></span>{fun JZLANG('是否必填')}
							</label>
							<div class="layui-input-inline">
								<input type="radio" name="ismust" value="1" title="{fun JZLANG('必填')}">
								<input type="radio" name="ismust" value="0" title="{fun JZLANG('非必填')}" checked>
							</div>
							<div class="layui-form-mid layui-word-aux">{fun JZLANG('带有文本框编辑器的除外')}</div>
						</div>
						<div class="layui-form-item" pane>
							<label for="isshow" class="layui-form-label">
								<span class="x-red"></span>{fun JZLANG('前台显示')}
							</label>
							<div class="layui-input-inline">
								<input type="radio" name="isshow" value="1" title="{fun JZLANG('显示')}" checked>
								<input type="radio" name="isshow" value="0" title="{fun JZLANG('不显示')}">
							</div>
						</div>
						<div class="layui-form-item" pane>
							<label for="ishome" class="layui-form-label">
								<span class="x-red"></span>{fun JZLANG('前台表单')}
							</label>
							<div class="layui-input-inline">
								<input type="radio" name="ishome" value="1" title="{fun JZLANG('显示')}" checked>
								<input type="radio" name="ishome" value="0" title="{fun JZLANG('不显示')}">
							</div>
						</div>
						<div class="layui-form-item" pane>
							<label for="isadmin" class="layui-form-label">
								<span class="x-red"></span>{fun JZLANG('后台显示')}
							</label>
							<div class="layui-input-inline">
								<input type="radio" name="isadmin" value="1" title="{fun JZLANG('显示')}" checked>
								<input type="radio" name="isadmin" value="0" title="{fun JZLANG('不显示')}">
							</div>
						</div>
						<div class="layui-form-item" pane>
							<label for="issearch" class="layui-form-label">
								<span class="x-red"></span>{fun JZLANG('后台搜索')}
							</label>
							<div class="layui-input-inline">
								<input type="radio" name="issearch" value="1" title="{fun JZLANG('显示')}">
								<input type="radio" name="issearch" value="0" title="{fun JZLANG('不显示')}" checked>
							</div>
							<div class="layui-form-mid layui-word-aux">{fun JZLANG('仅用于后台列表头部带有该字段搜索')}</div>
						</div>
						<div class="layui-form-item" pane>
							<label for="islist" class="layui-form-label">
								<span class="x-red"></span>{fun JZLANG('列表中显示')}
							</label>
							<div class="layui-input-inline">
								<input type="radio" name="islist" value="1" title="{fun JZLANG('显示')}">
								<input type="radio" name="islist" value="0" title="{fun JZLANG('不显示')}" checked>
							</div>
							<div class="layui-form-mid layui-word-aux">{fun JZLANG('仅用于后台列表显示该字段')}</div>
						</div>
						<div class="layui-form-item">
							<label for="format" class="layui-form-label">
								<span class="x-red"></span>{fun JZLANG('显示格式化')}
							</label>
							<div class="layui-input-inline">
								<select name="format" lay-filter="format" id="format">
									<option>{fun JZLANG('不做处理')}</option>
									{foreach format_fields() as $k=>$v}
									<option value="{$k}">{$v}</option>
									{/foreach}
								</select>
							</div>
							<div class="layui-form-mid layui-word-aux">{fun JZLANG('仅用于后台列表显示该字段内容处理')}</div>
						</div>
						<div class="layui-form-item" pane>
							<label for="isajax" class="layui-form-label">
								<span class="x-red"></span>{fun JZLANG('ajax可访问')}
							</label>
							<div class="layui-input-inline">
								<input type="radio" name="isajax" value="1" title="{fun JZLANG('可以')}" checked>
								<input type="radio" name="isajax" value="0" title="{fun JZLANG('不可以')}">
							</div>
							<div class="layui-form-mid layui-word-aux">{fun JZLANG('由于本系统对json数据封装，限制访问可以提高安全性')}</div>
						</div>
					</div>
					<div class="layui-tab-item">
						{if($molds=='level')}
						<table class="layui-table layui-form">
							<thead>
								<tr>
									<th width="20">
										<div class="layui-unselect header layui-form-checkbox layui-form-checked" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
									</th>
									<th>{fun JZLANG('角色名')}</th>
								</tr>
							</thead>
							<tbody class="x-cate">
								{php
									if($admin['gid']!=1){
										$levelgroup = M('level_group')->findAll('id!=1');
									}else{
										$levelgroup = M('level_group')->findAll();
									}
									$levelgroup = set_class_haschild($levelgroup);
									$levelgroup = getTree($levelgroup);
								/}
								{foreach $levelgroup as $v}
								<tr cate-id="{$v['id']}" fid="{$v['pid']}">
									<td>
										<div class="layui-unselect layui-form-checkbox layui-form-checked" lay-skin="primary" data-id='{$v['id']}'><i class="layui-icon">&#xe605;</i></div>
									</td>
									<td>
										{fun str_repeat('&nbsp;&nbsp;&nbsp;',$v['level'])}
										{if($v['haschild'])}
											<i class="layui-icon x-show" status='false'>&#xe625;</i>
										{else}
											{if($v['level'])}|——{/if}
										{/if}
										{$v['name']}
									</td>
								</tr>
								{/foreach}
							</tbody>
						</table>
						{else}
						<table class="layui-table layui-form">
							<thead>
								<tr>
									<th width="20">
										<div class="layui-unselect header layui-form-checkbox layui-form-checked" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
									</th>
									<th>{fun JZLANG('栏目名')}</th>
								</tr>
							</thead>
							<tbody class="x-cate">
								{foreach $classtypes as $v}
								{if($v['molds']==$molds || $molds=='classtype')}
								<tr cate-id="{$v['id']}" fid="{$v['pid']}">
									<td>
										<div class="layui-unselect layui-form-checkbox layui-form-checked" lay-skin="primary" data-id='{$v['id']}'><i class="layui-icon">&#xe605;</i></div>
									</td>
									<td>
										{fun str_repeat('&nbsp;&nbsp;&nbsp;',$v['level'])}
										{if($v['haschild'])}
											<i class="layui-icon x-show" status='false'>&#xe625;</i>
										{else}
											{if($v['level'])}|——{/if}
										{/if}
										{$v['classname']}
									</td>
								</tr>
								{/if}
								{/foreach}
							</tbody>
						</table>
						{/if}
					</div>
				</div>
			</div>
			<div class="layui-form-item" style="text-align:center;">
				<button class="layui-btn" lay-filter="save" lay-submit="">{fun JZLANG('保存')}</button>
			</div>
		</form>
	</div>

	<script>			
		layui.use(['laydate','form','layer','upload'], function(){
			$ = layui.jquery;
			var form = layui.form
				,layer = layui.layer
				,laydate = layui.laydate;	
			
			//监听提交
			form.on('submit(save)', function(data){
				var tids = tableCheck.getData().join(',');
				if(tids==''){
					//layer.alert('请选择绑定栏目！', {icon: 5});
					//return false;
					tids = 0;
				}
				data.field.tids = tids;
				data.field.field = data.field.field.toLowerCase()
				//发异步，把数据提交给php
				$.post("{fun U('Fields/addFields')}",data.field,function(r){					
					//console.log(r);return false;
					var r = JSON.parse(r);
					if(r.code==0){
						layer.msg(r.msg, {icon: 6,time: 2000},function () {
						// 获得frame索引
						{if($webconf['admintpl']=='tpl')}
						window.location.href="{fun U('Fields/index',['molds'=>$molds])}";
						{else}
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.layer.close(index);
							parent.location.reload();
						{/if}
					});
							
					}else{
						layer.alert(r.msg, {icon: 5});
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>